Skip to content

BUG: Construct Timestamp with tz correctly near DST border #21407

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Jun 13, 2018

Conversation

mroeschke
Copy link
Member

@mroeschke mroeschke commented Jun 10, 2018

closes #19970
closes #20854

  • tests added / passed
  • passes git diff upstream/master -u -- "*.py" | flake8 --diff
  • whatsnew entry

So I think the reason we need to convert a Timestamp to datetime branch is because of how Timestamp behave with normalize explained by this #18618 (comment)

@pep8speaks
Copy link

pep8speaks commented Jun 10, 2018

Hello @mroeschke! Thanks for updating the PR.

Cheers ! There are no PEP8 issues in this Pull Request. 🍻

Comment last updated on June 13, 2018 at 03:17 Hours UTC

@mroeschke mroeschke added the Timezones Timezone data dtype label Jun 10, 2018
@codecov
Copy link

codecov bot commented Jun 10, 2018

Codecov Report

Merging #21407 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master   #21407   +/-   ##
=======================================
  Coverage   91.89%   91.89%           
=======================================
  Files         153      153           
  Lines       49600    49600           
=======================================
  Hits        45580    45580           
  Misses       4020     4020
Flag Coverage Δ
#multiple 90.29% <ø> (ø) ⬆️
#single 41.86% <ø> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update ab668b0...ae9dc7b. Read the comment docs.

if ts.tzinfo is not None:
if hasattr(tz, 'normalize') and hasattr(ts.tzinfo, '_utcoffset'):
# tz.localize does not correctly localize Timestamps near DST
# but correctly localizes datetimes
if hasattr(ts, 'to_pydatetime'):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Elsewhere we've used not PyDatetimeCheckExact(ts) as a standin for isinstance(ts, pd.Timestamp). This might also be use case for the nanos kwarg.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @jbrockmendel. Seems clearer than trying to get Timestamp to quack

if ts.tzinfo is not None:
if hasattr(tz, 'normalize') and hasattr(ts.tzinfo, '_utcoffset'):
# tz.localize does not correctly localize Timestamps near DST
# but correctly localizes datetimes
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIRC tz.localize (or possibly tz.normalize if thats relevant) operates by calling ts methods. Is this potentially something we can fix "higher up" in Timestamp?

@@ -347,10 +347,9 @@ cdef _TSObject convert_datetime_to_tsobject(datetime ts, object tz,
if tz is not None:
tz = maybe_get_tz(tz)

# sort of a temporary hack
if ts.tzinfo is not None:
if hasattr(tz, 'normalize') and hasattr(ts.tzinfo, '_utcoffset'):
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This check might be superfluous since datetimes natively have the astimezone method. Then this whole block might be able to be simplified.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm, you can try that and see if it works. maybe add a comment anyhow

@jreback jreback added this to the 0.23.2 milestone Jun 12, 2018
@jreback jreback added Bug Indexing Related to indexing on series/frames, not to indexes themselves labels Jun 12, 2018
@@ -129,6 +129,10 @@ Bug Fixes
- Bug in :func:`concat` where error was raised in concatenating :class:`Series` with numpy scalar and tuple names (:issue:`21015`)
- Bug in :func:`concat` warning message providing the wrong guidance for future behavior (:issue:`21101`)

**Timezones**
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

move to 0.23.2

@@ -992,6 +992,16 @@ def test_boolean_comparison(self):
result = df == tup
assert_frame_equal(result, expected)

@pytest.mark.parametrize('tz', [None, 'America/New_York'])
def test_boolean_compare_transpose_tzindex_with_dst(self, tz):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you move to test_timezones

@@ -347,10 +347,9 @@ cdef _TSObject convert_datetime_to_tsobject(datetime ts, object tz,
if tz is not None:
tz = maybe_get_tz(tz)

# sort of a temporary hack
if ts.tzinfo is not None:
if hasattr(tz, 'normalize') and hasattr(ts.tzinfo, '_utcoffset'):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm, you can try that and see if it works. maybe add a comment anyhow

@jreback jreback merged commit bc4ccd7 into pandas-dev:master Jun 13, 2018
@jreback
Copy link
Contributor

jreback commented Jun 13, 2018

thanks @mroeschke nice clean up!

can you review any outstanding issues that involve dst. this may go a long way towards solving them (if so, then pls PR for tests).

@mroeschke mroeschke deleted the correct_normalize branch June 13, 2018 15:33
david-liu-brattle-1 pushed a commit to david-liu-brattle-1/pandas that referenced this pull request Jun 18, 2018
jorisvandenbossche pushed a commit that referenced this pull request Jun 29, 2018
jorisvandenbossche pushed a commit that referenced this pull request Jul 2, 2018
Sup3rGeo pushed a commit to Sup3rGeo/pandas that referenced this pull request Oct 1, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Indexing Related to indexing on series/frames, not to indexes themselves Timezones Timezone data dtype
Projects
None yet
5 participants